package qmlt.learning.bagging;

import qmlt.learning.Learner;

@SuppressWarnings("unchecked")
public class BaggingControllerWithFactory<P, L extends Learner<P>> extends BaggingController<P, L>
{

    public interface LearnerFactory<L>
    {
        L get() throws Exception;
    }
    
    private LearnerFactory<L> factory;
    
		public BaggingControllerWithFactory(LearnerFactory factory, P controller, int nReplicates,
            int replicateSizePercentage)
    {
        super(null, controller, nReplicates, replicateSizePercentage);
        this.factory = factory;
    }
    
    @Override
    public L getBaggedLearnerInstance()
    {
        try
        {
            return factory.get();
        }
        catch (Exception e)
        {
            System.err.println("failed to create a learner instance: " + e.getMessage());
            e.printStackTrace();
            return null;
        }
    }

}
